<?php
require '../model/topicDao.php';

if($_SERVER["REQUEST_METHOD"] == "GET") {
    $topicId = $_GET['topicId'];
    
    // 可以添加权限验证，确保只有帖子作者或管理员可以删除
    // if($_SESSION['userid'] != $authorId && $_SESSION['role'] != 'admin') {
    //     echo json_encode(["status" => "error", "message" => "没有权限"]);
    //     exit;
    // }
    
    $result = delete_topic($topicId);
    
    if($result) {
        echo json_encode(["status" => "success", "message" => "帖子已删除"]);
        header("location:../views/me.php");
    } else {
        echo json_encode(["status" => "error", "message" => "删除失败"]);
    }
} else {
    header("location:../views/error.php?msg=非法访问");
}
?> 